<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets">

<ui:composition template="/templates/template.xhtml">
	<p:growl id="growl" showDetail="true" sticky="true" />
	<ui:define name="title">
		<h:outputText value="#{lbls.LBL_0098}" />
	</ui:define>

	<ui:define name="head">
		<style type="text/css">
#panelGrid1 {
	width: 100%;
	border-style: none;
	border-width: 0px;
}

.colunaPanelGrid1 {
	border-width: 0px;
	border-style: none;
}

.colDir {
	text-align: right;
}

.colEsq {
	text-align: left;
}
</style>

	</ui:define>

	<ui:define name="centro">
		<h:form id="form1" prependId="false">
			<p:panel id="painelEdicao">
				<f:facet name="header">
					<h:outputText value="#{lbls.LBL_0098}" />
				</f:facet>
				<h:panelGrid columns="2" width="99%">
					<h:outputLabel value="#{lbls.LBL_0102}:" for="dataInicial"
						id="lblDataInicial" />
					<p:calendar value="#{relatorioVendasMB.dataInicial}"
						pattern="dd/MM/yyyy" id="dataInicial" showOn="button" />
					<h:outputLabel value="#{lbls.LBL_0103}:" for="dataFinal"
						id="lblDataFinal" />
					<p:calendar value="#{relatorioVendasMB.dataFinal}" id="dataFinal"
						pattern="dd/MM/yyyy" showOn="button" />

					<p:outputLabel value="#{lbls.LBL_0006}:" for="comboMarcas" />
					<p:selectOneMenu id="comboMarcas" label="#{lbls.LBL_0006}"
						style="width:234px;"
						value="#{relatorioVendasMB.marcaProduto}"
						converter="selectOneConverter"
						itens="#{relatorioVendasMB.listaDeMarcas}">
						<f:selectItem itemLabel="#{lbls.LBL_0028}" />
						<f:selectItems value="#{relatorioVendasMB.listaDeMarcas}"
							var="marcaProduto" itemLabel="#{marcaProduto.nome}"
							itemValue="#{marcaProduto}" />
					</p:selectOneMenu>

					<p:outputLabel value="#{lbls.LBL_0007}:" for="comboGrupo" />
					<p:selectOneMenu id="comboGrupo" style="width:120px;"
						label="#{lbls.LBL_0007}"
						value="#{relatorioVendasMB.grupoProduto}"
						converter="selectOneConverter"
						itens="#{relatorioVendasMB.listaDeGrupos}">
						<f:selectItem itemLabel="#{lbls.LBL_0028}" />
						<f:selectItems value="#{relatorioVendasMB.listaDeGrupos}"
							var="grupoProduto" itemLabel="#{grupoProduto.nome}"
							itemValue="#{grupoProduto}" />
					</p:selectOneMenu>
					
					<p:outputLabel value="#{lbls.LBL_0083}:" for="comboProdutos" />
					<p:selectOneMenu id="comboProdutos" label="#{lbls.LBL_0083}"
						style="width:234px;"
						value="#{relatorioVendasMB.produto}"
						converter="selectOneConverter"
						itens="#{relatorioVendasMB.listaDeProdutos}">
						<f:selectItem itemLabel="#{lbls.LBL_0028}" />
						<f:selectItems value="#{relatorioVendasMB.listaDeProdutos}"
							var="produto" itemLabel="#{produto.descricao}"
							itemValue="#{produto}" />
					</p:selectOneMenu>
				</h:panelGrid>

				<f:facet name="footer">
					<p:commandButton value="#{lbls.LBL_0078}" icon="ui-icon-cancel"
						update="vendasDataTable" process="@this dataInicial dataFinal"
						action="#{relatorioVendasMB.doListarAction}" />

				</f:facet>

				<p:confirmDialog id="confirmDialog" message="#{msgs.MSG_0002}"
					appendToBody="true" header="#{msgs.MSG_0003}" severity="alert"
					widgetVar="confirmation">

					<p:commandButton id="decline" value="#{lbls.LBL_0012}"
						onclick="confirmation.hide()" type="button" />

				</p:confirmDialog>
			</p:panel>

			<p:dataTable id="vendasDataTable" var="venda" paginator="true"
				rows="5" emptyMessage="#{lbls.LBL_0004}" paginatorPosition="bottom"
				rowKey="#{venda.id}" value="#{relatorioVendasMB.listaVendas}"
				paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}">
				<p:column style="width:10px;">
					<f:facet name="header">
						<h:outputText value="#{lbls.LBL_0005}" />
					</f:facet>
					<div align="center">
						<h:outputText value="#{venda.id}" />
					</div>
				</p:column>

				<p:column style="text-aling:center;">
					<f:facet name="header">
						<h:outputText value="#{lbls.LBL_0101}" />
					</f:facet>
					<h:outputText value="#{venda.dataVenda}">
						<f:convertDateTime pattern="dd/MM/yyyy - HH:mm" />
					</h:outputText>
				</p:column>

				<p:column styleClass="colDir">
					<f:facet name="header">
						<h:outputText value="Valor (R$)" />
					</f:facet>
					<h:outputText value="#{venda.valor}">
						<f:convertNumber type="currency" currencySymbol="" />
					</h:outputText>
				</p:column>

				<p:column styleClass="colDir">
					<f:facet name="header">
						<h:outputText value="Desc. (%)" />
					</f:facet>
					<h:outputText value="#{venda.percDesconto}" />
				</p:column>

				<p:column styleClass="colDir">
					<f:facet name="header">
						<h:outputText value="Desc. (R$)" />
					</f:facet>
					<h:outputText value="#{venda.valorFinal}">
						<f:convertNumber type="currency" currencySymbol="" />
					</h:outputText>
				</p:column>

				<p:column styleClass="colDir">
					<f:facet name="header">
						<h:outputText value="Total (R$)" />
					</f:facet>
					<h:outputText value="#{venda.valorFinal}">
						<f:convertNumber type="currency" currencySymbol="" />
					</h:outputText>
				</p:column>

				<p:column style="width:40px">
					<p:commandButton id="showDialogButton" icon="ui-icon-search"
						oncomplete="vendaDialog.show()"
						action="#{relatorioVendasMB.doBuscarVendaAction}" process="@this"
						update="@(#itemVendaDataTable, #dadosVenda, #formaPagtoDataList, #panelDesc)">
						<f:setPropertyActionListener value="#{venda}"
							target="#{relatorioVendasMB.vendaSelecionada}" />
					</p:commandButton>
				</p:column>
			</p:dataTable>


			<p:dialog id="dialog" header="Detalhes da Venda"
				widgetVar="vendaDialog" modal="true" draggable="false"
				resizable="false" appendToBody="true" showEffect="explode"
				hideEffect="explode" maximizable="true">

				<p:panelGrid columns="3" id="dadosVenda">
					<h:outputText value="Data:" />
					<h:outputText
						value="#{relatorioVendasMB.vendaSelecionada.dataVenda}">
						<f:convertDateTime />
					</h:outputText>
				</p:panelGrid>

				<table width="325px" border="0">
					<tr valign="top">
						<td width="60%"><h:dataTable id="formaPagtoDataList"
								value="#{relatorioVendasMB.listaFormasPagamento}"
								var="formaPgto">

								<h:column>
									<h:outputText value="#{formaPgto.tipoPagamento.descricao}:" />
								</h:column>

								<h:column>
									<h:outputText value="#{formaPgto.qtdaParcelas} x " />
								</h:column>

								<h:column>
									<h:outputText value="#{formaPgto.valorParcela}">
										<f:convertNumber type="currency" currencySymbol="" />
									</h:outputText>
									<h:outputText value=" = " />
								</h:column>

								<h:column>

									<f:facet name="footer">
										<h:outputText style="text-decoration:overline;"
											value="#{relatorioVendasMB.vendaSelecionada.valor}">
											<f:convertNumber type="currency" currencySymbol="" />
										</h:outputText>
									</f:facet>

									<h:outputText value="#{formaPgto.valorTotal}">
										<f:convertNumber type="currency" currencySymbol="" />
									</h:outputText>
								</h:column>

							</h:dataTable></td>
						<td><h:panelGrid columns="2" id="panelDesc" width="140px;">
								<h:outputText value="Total:" />
								<h:outputText
									value="#{relatorioVendasMB.vendaSelecionada.valor}">
									<f:convertNumber type="currency" currencySymbol="" />
								</h:outputText>
								<h:outputText value="Desc.:" />

								<h:panelGroup>
									<h:outputText
										value="#{relatorioVendasMB.vendaSelecionada.valorDesconto}">
										<f:convertNumber type="currency" currencySymbol="" />
									</h:outputText>
									<h:outputText value=" (" />
									<h:outputText
										value="#{relatorioVendasMB.vendaSelecionada.percDesconto}">
										<f:convertNumber pattern="#,##0.00" minFractionDigits="1" />
									</h:outputText>
									<h:outputText value="%) -" />
								</h:panelGroup>
								<h:outputText value="" />
								<h:outputText styleClass="colDir"
									style="text-decoration:overline;"
									value="#{relatorioVendasMB.vendaSelecionada.valorFinal}">
									<f:convertNumber type="currency" currencySymbol="" />
								</h:outputText>
							</h:panelGrid></td>
					</tr>
				</table>

				<p:dataTable id="itemVendaDataTable" var="itemVenda"
					paginator="true" rows="15" emptyMessage="#{lbls.LBL_0004}"
					paginatorPosition="bottom"
					value="#{relatorioVendasMB.listaItemVenda}"
					paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}">

					<p:column>
						<f:facet name="header">
							<h:outputText value="Produto" />
						</f:facet>
						<h:outputText value="#{itemVenda.produto.descricao}" />

						<f:facet name="footer">
							<h:outputText value="Total:" style="text-align:right" />
						</f:facet>
					</p:column>

					<p:column styleClass="colDir" style="width: 30px;">
						<f:facet name="header">
							<h:outputText value="Qtda." />
						</f:facet>
						<h:outputText value="#{itemVenda.quantidade}" />

						<f:facet name="footer">
							<h:outputText value="#{relatorioVendasMB.totalItensVendidos}"
								style="text-align:right" />
						</f:facet>
					</p:column>

					<p:column styleClass="colDir" style="width: 90px;">
						<f:facet name="header">
							<h:outputText value="#{lbls.LBL_0049} (R$)" />
						</f:facet>
						<h:outputText
							value="#{itemVenda.produto.valorVenda * itemVenda.quantidade}">
							<f:convertNumber type="currency" currencySymbol="" />
						</h:outputText>

						<f:facet name="footer">
							<h:outputText
								value="#{relatorioVendasMB.vendaSelecionada.valorFinal}">
								<f:convertNumber type="currency" currencySymbol="" />
							</h:outputText>
						</f:facet>

					</p:column>

				</p:dataTable>
			</p:dialog>

		</h:form>
	</ui:define>
</ui:composition>
</html>